﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Learn._003SinglePageApp
{
    class Mail
    {
        public int id { get; set; }
        public string from { get; set; }
        public string to { get; set; }
        public string subject { get; set; }

        public string date { get; set; }
        public string folder { get; set; }
        public string messageCountent { get; set; }
                      
    }
    class MailsByType
    {
        public string id { get; set; }
        public List<Mail> mails { get; set; }
    }
    public partial class a : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            var ser = new System.Web.Script.Serialization.JavaScriptSerializer();
            var ls = new List<Mail>() { 
                new Mail{ id=1,from="from",to ="to", subject="subject",date="date",folder="folder",messageCountent="messageContent<br/>sdf<script>alert('xxx')</script>"},
                new Mail{ id=2, from="from",to ="to" ,subject="subject",date="date",folder="folder",messageCountent="messageContent<br/>sdf<script>alert('xxx')</script>"},
            };
            if (Request.QueryString["cmd"] == "getMails")
            {
                var mailsByType = new MailsByType()
                {
                    id = "xxx",
                    mails = ls
                };
                var jsonStr = ser.Serialize(mailsByType);
                Response.Clear();
                Response.Write(jsonStr);
                Response.End();

            }
            else if (Request.QueryString["cmd"] == "getMail")
            {
                var id = int.Parse(Request.QueryString["mailId"]);
                var mail = ls.Where(i => i.id == id).FirstOrDefault();
                Response.Clear();
                Response.Write(ser.Serialize(mail));
                Response.End();
            }

        }
    }
}